package com.kgc.controller.user;

import com.kgc.common.Result;
import com.kgc.entity.User;
import com.kgc.service.interf.user.OwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hyj
 * @time 2024/4/2 15:56
 * @describe
 */
@RestController
@RequestMapping("/apis/user/owner")
public class OwnerController {
    @Autowired
    private OwnerService ownerService;

    @RequestMapping("/info/{userId}")
    public String getOwner(@PathVariable("userId") Integer userId) {
        User owner = ownerService.getOwner(userId);
        if (owner == null) {
            return Result.success("1", "failed");
        }
        return Result.success("0", "success", owner);
    }

    @RequestMapping("/update")
    public String updateOwner(String username, String email, Integer userId) {
        int i = ownerService.updateOwner(userId, username, email);
        if (i == -1) {
            return Result.success("-1", "该用户名已存在，请重新输入");
        } else if (i == -2) {
            return Result.success("-2", "该邮箱已存在，请重新输入");
        } else if (i == 1) {
            return Result.success("0", "修改成功");
        }
        return Result.success("1", "修改失败");
    }
}
